/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.grass.plugin.dialect;

import com.grass.plugin.paging.page.Page;

/**
 * @author wujx
 * QQ 396246973
 * Date 2013-02-10
 */
public class MsSQLDialect extends Dialect {

	@Override
    public String getLimitString(String sql, Page page) {
        if (page.isPagination() == false) {
            return sql;
        }
        int startOfSelect =hasDistinct(sql)? sql.toLowerCase().indexOf("distinct") + 8: sql.toLowerCase().indexOf("select") + 6;
        StringBuffer pagingSelect = new StringBuffer(sql.length() + 20);
        pagingSelect.append(sql.substring(0, startOfSelect));
        pagingSelect.append(" top " + page.getPageEndRow());
        pagingSelect.append(sql.substring(startOfSelect));
        return pagingSelect.toString().trim();
    }
	
	public boolean NativePaging(){
		   return false;
	   }
}
